package com.qimu.saiyou.model.vo;

import cn.hutool.json.JSONUtil;
import com.qimu.saiyou.model.entity.Competition;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;

/**
 * 帖子视图
 *
 *@author: FeiXiang
 * 
 */
@Data
public class CompetitionVO implements Serializable {

    private static final long serialVersionUID = -4578891853558315271L;
    private Long id;

    /**
     * 竞赛名称
     */
    private String competitionName;
    private Long userId;
    /**
     * 标签列表
     */
    private List<String> tagList;
    /**
     * 竞赛头像
     */
    private String competitionAvatarUrl;

    /**
     * 最大参与人数
     */
    private Long maxNum;

    /**
     * 创建人
     */
    private UserVO user;

    /**
     * cancel - 取消，end - 结束，running - 进行中，signingUp-报名中
     */
    private String competitionStatus;

    /**
     * 竞赛类型 ；0-线上赛|1-线下赛
     */
    private Integer competitionType;

    /**
     * 竞技模式 0-单人|1-多人
     */
    private Integer competitiveMode;

    /**
     * 队伍最大参与人数
     */
    private Long teamMaxNum;

    /**
     * 竞赛公告
     */
    private String announce;


    /**
     * 竞赛规则
     */
    private String rules;

    /**
     * 竞赛地点
     */
    private String address;

    /**
     * 竞赛奖励
     */
    private String reward;

    /**
     * 报名截止时间
     */
    private String signUpDeadline;

    /**
     * 竞赛结束时间
     */
    private String endTime;


    /**
     * 包装类转对象
     *
     * @param competitionVO
     * @return
     */
    public static Competition voToObj(CompetitionVO competitionVO) {
        if (competitionVO == null) {
            return null;
        }
        Competition competition = new Competition();
        BeanUtils.copyProperties(competitionVO, competition);
        List<String> tagList = competitionVO.getTagList();
        competition.setTags(JSONUtil.toJsonStr(tagList));
        return competition;
    }

    /**
     * 对象转包装类
     *
     * @param competition
     * @return
     */
    public static CompetitionVO objToVo(Competition competition) {
        if (competition == null) {
            return null;
        }
        CompetitionVO competitionVO = new CompetitionVO();
        BeanUtils.copyProperties(competition, competitionVO);
        competitionVO.setTagList(JSONUtil.toList(competition.getTags(), String.class));
        return competitionVO;
    }
}
